#!/usr/bin/env python
# -*- coding:utf-8 -*-
from flask import request, Flask
from utils.rss import *
from utils.PyAria2 import *

app = Flask(__name__)
RSS_URL = "https://www.torlock.com/movies/rss.xml"


@app.route('/')
def index():
    """
    服务状态检查，保证服务正常
    :return:
    """
    return "OK"


# @app.route("/aria2/callback", methods=["POST"])
# # def callback():
# #     gid = request.form["gid"]
# #     count = request.form["count"]
# #     path = request.form["path"]
# #     print gid, count, path
# #     file_name = os.path.basename(path)
# #     title = "The file [{}] been done!".format(file_name)
# #     data = {"text": title, "desp": file_name}
# #     do_post("https://sc.ftqq.com/SCU29915Te34d0c9fc1c1d1b00ece58a02c2428b25b59ba5282c4f.send", data)
# #     cmd = "/usr/local/bin/onedrive -f /movie %s  && rm -rf %s" % (path, path)
# #     os.system(cmd)
# #     return gid


@app.route("/serverjian/callback", methods=["GET"])
def callback():
    result = request.args.get('result')
    uid = request.args.get('id')
    if result:
        update_test(uid,result)
        mag_link = fetchone_test(uid)[0][2]
        py_aria_client = PyAria2()
        py_aria_client.addUri(mag_link)
    return "ok"


@app.route("/rss/start")
def start():
    rss = Rss(1, rss_url=RSS_URL)
    rss.start()
    return "线程启动 OK"


if __name__ == "__main__":
    app.run(debug=True)
